#include <stdio.h>
#define SIZE 20000

int
main (void)
{
	int gr[SIZE], n, m, now, after;
	short changed[SIZE];
	register unsigned short i = 0, j = 0;

	freopen("election.in", "r", stdin);
	freopen("election.out", "w", stdout);

	scanf("%d", &n);
	while (i < n) {
		changed[i] = 0;
		scanf("%d", &gr[i++]);
	}
	scanf("%d", &m);
	i=0;
/*	for (j=0; j<n; j++)
		fprintf(stderr, "%d %d\n", gr[j], changed[j]);
	fprintf(stderr, "--\n");	*/
	while (i++ < m) {
		scanf("%d %d", &now, &after);
		for (j = 0; j < n; j++) {
			if (changed[j])
				continue;
			else if (gr[j] == now) {
				gr[j] = after;
				changed[j] = 1;
			}
		}
	/*	for (j=0; j<n; j++)
			fprintf(stderr, "%d %d\n", gr[j], changed[j]);
		fprintf(stderr, "--\n");	*/
	}
	for (i = 0; i < n; i++)
		printf("%d ", gr[i]);
	printf("\n");
	return 0;
}
